﻿using EmployeeCard.Api.Filtter;
using EmployeeCard.IServices;
using EmployeeCard.Model.Models;
using EmployeeCard.Services;

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace EmployeeCard.Api.Controllers
{
    /// <summary>
    /// 接口控制器
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    //[Authorize(Policy ="Admin")]
    public class EmployeeCardController : ControllerBase
    {
        private IAdvertisementServices _advertisementServices;
        public EmployeeCardController(IAdvertisementServices advertisementServices)
        {
            _advertisementServices = advertisementServices;
        }
        /// <summary>
        /// 给两个数字求和
        /// </summary>
        /// <param name="num1"></param>
        /// <param name="num2"></param>
        /// <returns></returns>
        [HttpGet]
        public int Get(int num1,int num2)
        {
            return _advertisementServices.Sum(num1, num2);
        }

        /// <summary>
        /// 根据id获取数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id}")]
        public Task<List<Advertisement>> GetList(int id)
        {
            return _advertisementServices.Query(x => x.Id == id);
        }

        /// <summary>
        /// 添加广告
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<int> Add([FromBody] Advertisement model)
        {
            return _advertisementServices.Add(model);
        }

        /// <summary>
        /// 修改广告
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<bool> Update([FromBody] Advertisement model)
        {
            return _advertisementServices.Update(model);
        }

        /// <summary>
        /// 删除广告
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpDelete]
        public Task<bool> Delete([FromBody] Advertisement model)
        {
            return _advertisementServices.Delete(model);
        }

    }
}
